package org.example.seckilljava.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.seckilljava.entity.SeckillStock;

@Mapper
public interface SeckillStockMapper extends BaseMapper<SeckillStock> {
    @Update("update t_seckill_stock set stock = stock - #{num} where goods_id = #{goodsID} and stock >= #{num}")
    Integer descStock(@Param("goodsID") Long goodsID, @Param("num") Integer num);

    @Select("select t_seckill_stock.stock from t_seckill_stock where goods_id = #{goodsID}")
    int getStock(@Param("goodsID") Long goodsID);
}